package initialize

import "github.com/wagslane/go-rabbitmq"

var RabbitMQConnect *rabbitmq.Conn

func RabbitMQInit() {
	hostName := Env("rabbitmq", "host").Value()
	hostPort := Env("rabbitmq", "port").Value()
	username := Env("rabbitmq", "user").Value()
	password := Env("rabbitmq", "password").Value()

	rabbitmqDns := "amqp://" + username + ":" + password + "@" + hostName + ":" + hostPort

	conn, err := rabbitmq.NewConn(
		rabbitmqDns,
		rabbitmq.WithConnectionOptionsLogging,
	)

	if err != nil {
		panic("连接RabbitMQ失败：" + err.Error())
	}

	RabbitMQConnect = conn
	return
}
